package com.zyb.insurance.policy;

import java.io.*;

public class tt {

    private static FileWriter writer =null;

    public static void main(String[] args) {
        File baseFile = new File("F:\\快递地址数据\\address");
        File[] files =baseFile.listFiles();
        //File file = new File("F:\\快递地址数据\\address-08\\xah");
        for (File file : files) {
            try{
                BufferedReader br = new BufferedReader(new FileReader(file));//构造一个BufferedReader类来读取文件
                String s = null;
                writer = new FileWriter("F:\\快递地址数据\\脱敏地址\\out-012.txt", true);
                while((s = br.readLine())!=null){//使用readLine方法，一次读一行
                    String[] res=s.split("\u0001");
                    if (res.length==3) {
                        writeFile1(res[2]);
                    }
                }
                br.close();
                writer.close();
            }catch(Exception e){
                e.printStackTrace();
            }
        }
    }

    public static void writeFile1(String content) throws IOException {
//        try {
//            File file =new File("F:\\快递地址数据\\脱敏地址\\out.txt");
//            if(!file.exists()){
//                file.createNewFile();
//            }
//            FileWriter fileWritter = new FileWriter(file.getName(),true);
//            BufferedWriter bufferWritter = new BufferedWriter(fileWritter);
//            //bufferWritter.newLine();
//            bufferWritter.write(content+"\r\n");
//            bufferWritter.close();
//
//            System.out.println("Done");
//        } catch (IOException e) {
//        }

        try {
            // 打开一个写文件器，构造函数中的第二个参数true表示以追加形式写文件
            writer.write(content+"\r\n");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
